//进入页面 从locals中取出数据进行顶部欢迎栏的渲染

function showInformation() {
    let userInfo = JSON.parse(localStorage.getItem('USER'))
    if (userInfo) {
        let userStr = userInfo.visitgoal
        $('.login span:first-child').html(`${userStr}欢迎您`)
        $('.logOut').html('退出登录')
        $('.logOut').on('click', function () {
            if (localStorage.getItem('USER')) {
                localStorage.removeItem('USER')
                location.href = './index.html'
            } else {

                alert('当前用户未登录，请先登录')
            }
        })

    } else {
        $('.logOut').html('点击登录')
        $('.logOut').on('click', function () {
            location.href = './login.html'
        })
    }

}

showInformation()


//查看购物车
function cart() {
    $('.cart').on('click', function () {
        location.href = './cartList.html'
    })
}

cart()

//点击返回顶部

$('#aside').on('click', function () {
    let timer = setInterval(function () {
        if (document.documentElement.scrollTop == 0) {
            clearInterval(timer)
        } else {
            document.documentElement.scrollTop -= 20
        }
    }, 1)

})

$('.freeRegister').on('click', function () {
    location.href = '../pages/register.html'
})